var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/functionalComponent/table/hook/useValue.ts
var useValue_exports = {};
__export(useValue_exports, {
  useValue: () => useValue
});
module.exports = __toCommonJS(useValue_exports);
var import_react = require("react");
var import_util = require("../util");
function useValue(value, isHelp) {
  const ref = (0, import_react.useRef)({ value, forceUpdate: false });
  const [forceUpdate, setForceUpdate] = (0, import_react.useState)({ value });
  (0, import_react.useMemo)(() => {
    const oldValue = ref.current.value;
    if (isHelp && (import_util.util.isObject(oldValue) || import_util.util.isArray(oldValue))) {
      const tmp = import_util.util.isArray(oldValue) ? oldValue.map((v) => v.value ?? v).join(",") : oldValue.value ?? oldValue;
      if (tmp === value) {
        return;
      }
    }
    ref.current.value = value;
    ref.current.forceUpdate = true;
  }, [value, isHelp]);
  const update = (0, import_util.useRefCallback)((newValue, callback, _forceUpdate) => {
    ref.current.value = newValue;
    ref.current.callback = callback;
    if (_forceUpdate || ref.current.value !== forceUpdate.value || ref.current.forceUpdate) {
      ref.current.forceUpdate = false;
      setForceUpdate({ value: newValue });
    }
  });
  (0, import_util.useIUPEffect)(
    () => {
      var _a, _b;
      (_b = (_a = ref.current).callback) == null ? void 0 : _b.call(_a, forceUpdate.value);
    },
    [forceUpdate],
    false
  );
  return [ref.current.value, update];
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useValue
});
